<?php
/**
 * @author spenceryg
 * @date 2022/4/11
 * @time 8:40 上午
 * @focus love & life
 */


namespace app\wechat\controller;


use app\BaseController;
use app\wechat\lib\MessageHandler;
use app\wechat\lib\QrcodeLogin;
use Cassandra\Uuid;
use EasyWeChat\Kernel\Messages\Message;
use think\App;
use think\facade\Log;
use EasyWeChat\Factory;

class Index extends BaseController
{



    public $wechat = null;

    public function __construct(App $app)
    {
        $config = config('wechat_official_account');

        $this->wechat = Factory::officialAccount($config);

        $this->wechat->server->push(QrcodeLogin::class, Message::EVENT);
        $this->wechat->server->push(MessageHandler::class, Message::TEXT);

        parent::__construct($app);
    }

    /**
     * index
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function index(){
//        return $this->wechat->server->serve();
        $response = $this->wechat->server->serve();
        $response->send();exit;
    }



}
